package com.wswy.wzcx.ui.njdb

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import com.wswy.wzcx.api.Api
import com.wswy.wzcx.model.license.UserCarInfo
import com.wswy.wzcx.model.njdb.NjdbPreModel
import com.wswy.wzcx.module.CarsViewModel
import com.wswy.wzcx.module.base.Resource
import com.wswy.wzcx.module.base.SingleLiveData
import com.wswy.wzcx.module.base.onResult

class NjServiceViewModel : CarsViewModel() {

    private val carUpdateLiveData = SingleLiveData<UserCarInfo>()

    private val preOrderLiveData = MutableLiveData<Resource<NjdbPreModel?>>()

    override fun onCreate() {
        super.onCreate()
        loadMyCars(false)
    }

    override fun onUserCarExtendInfoUpdate(userCarInfo: UserCarInfo) {
        super.onUserCarExtendInfoUpdate(userCarInfo)

        carUpdateLiveData.postValue(userCarInfo)
    }


    fun getCarUpdateLiveData():LiveData<UserCarInfo> = carUpdateLiveData


    fun getPreOrder(userCarId:Int):LiveData<Resource<NjdbPreModel?>>{

        addRun(Api.get().getInspectionModel(userCarId).onResult(preOrderLiveData))

        return preOrderLiveData
    }

}